package com.cms.admin.service.voice.impl;

import com.cms.admin.mapper.VoiceOnDemondDataMapper;
import com.cms.admin.mapper.VoiceOnDemondMapper;
import com.cms.admin.model.*;
import com.cms.admin.service.voice.VoiceService;

import java.util.List;

/**
 * Created by YYY on 2017/7/15.
 */
public class VoiceServiceImpl implements VoiceService {

    private VoiceOnDemondMapper voiceOnDemondMapper;
    private VoiceOnDemondDataMapper voiceOnDemondDataMapper;

    @Override
    public List<VoiceOnDemond> queryVoiceOnDemondList(PageBean page, VoiceOnDemondExt example) {
        long count = getRowCount(example);
        page.setAllRow(count);
        example.setOffset(page.getOffset());
        example.setPageSize(page.getPageSize());
        return voiceOnDemondMapper.selectByConditionWithLimit(example);
    }

    @Override
    public long getRowCount(VoiceOnDemondExt example) {
        return voiceOnDemondMapper.countByCondition(example);
    }

    @Override
    public VoiceOnDemond queryVoiceOnDemondDetail(Long recid) {
        return voiceOnDemondMapper.selectByPrimaryKey(recid);
    }

    @Override
    public long voiceCountByDemondId(VoiceOnDemondData record) {
        return voiceOnDemondDataMapper.countByDemondId(record);
    }

    @Override
    public List<VoiceOnDemondData> queryVoiceOnDemondDataList(PageBean page, VoiceOnDemondDataExt example) {
        long count = voiceCountByDemondId(example);
        page.setAllRow(count);
        example.setOffset(page.getOffset());
        example.setPageSize(page.getPageSize());
        return voiceOnDemondDataMapper.selectByDemondIdWithLimit(example);
    }

    @Override
    public int addVoiceSubject(VoiceOnDemond record) {
        return voiceOnDemondMapper.insertSelectiveAndGetId(record);
    }

    @Override
    public int addVoiceOnDemondDate(VoiceOnDemondDataExt example) {
        return voiceOnDemondDataMapper.insertSelectiveAndGetId(example);
    }

    @Override
    public int uploadVoiceOnDemondDate(VoiceOnDemondData example) {
        return voiceOnDemondDataMapper.updateByPrimaryKeySelective(example);
    }

    @Override
    public int uploadVoiceSubject(VoiceOnDemond record) {
        return voiceOnDemondMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public VoiceOnDemondData queryVoiceOnDemondDataDetail(Long recid) {
        return voiceOnDemondDataMapper.selectByPrimaryKey(recid);
    }

    @Override
    public int deleteVoiceOnDemondData(Long recid) {
        return voiceOnDemondDataMapper.deleteByPrimaryKey(recid);
    }

    public VoiceOnDemondMapper getVoiceOnDemondMapper() {
        return voiceOnDemondMapper;
    }

    public void setVoiceOnDemondMapper(VoiceOnDemondMapper voiceOnDemondMapper) {
        this.voiceOnDemondMapper = voiceOnDemondMapper;
    }

    public VoiceOnDemondDataMapper getVoiceOnDemondDataMapper() {
        return voiceOnDemondDataMapper;
    }

    public void setVoiceOnDemondDataMapper(VoiceOnDemondDataMapper voiceOnDemondDataMapper) {
        this.voiceOnDemondDataMapper = voiceOnDemondDataMapper;
    }
}
